home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / lib / python2.6 / stringold.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-11-11  |  13KB  |  412 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Common string manipulations.
  5.  
  6. Public module variables:
  7.  
  8. whitespace -- a string containing all characters considered whitespace
  9. lowercase -- a string containing all characters considered lowercase letters
  10. uppercase -- a string containing all characters considered uppercase letters
  11. letters -- a string containing all characters considered letters
  12. digits -- a string containing all characters considered decimal digits
  13. hexdigits -- a string containing all characters considered hexadecimal digits
  14. octdigits -- a string containing all characters considered octal digits
  15.  
  16. '''
  17. from warnings import warnpy3k
  18. warnpy3k('the stringold module has been removed in Python 3.0', stacklevel = 2)
  19. del warnpy3k
  20. whitespace = ' \t\n\r\x0b\x0c'
  21. lowercase = 'abcdefghijklmnopqrstuvwxyz'
  22. uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  23. letters = lowercase + uppercase
  24. digits = '0123456789'
  25. hexdigits = digits + 'abcdef' + 'ABCDEF'
  26. octdigits = '01234567'
  27. _idmap = ''
  28. for i in range(256):
  29.     _idmap = _idmap + chr(i)
  30.  
  31. del i
  32. index_error = ValueError
  33. atoi_error = ValueError
  34. atof_error = ValueError
  35. atol_error = ValueError
  36.  
  37. def lower(s):
  38.     '''lower(s) -> string
  39.  
  40.     Return a copy of the string s converted to lowercase.
  41.  
  42.     '''
  43.     return s.lower()
  44.  
  45.  
  46. def upper(s):
  47.     '''upper(s) -> string
  48.  
  49.     Return a copy of the string s converted to uppercase.
  50.  
  51.     '''
  52.     return s.upper()
  53.  
  54.  
  55. def swapcase(s):
  56.     '''swapcase(s) -> string
  57.  
  58.     Return a copy of the string s with upper case characters
  59.     converted to lowercase and vice versa.
  60.  
  61.     '''
  62.     return s.swapcase()
  63.  
  64.  
  65. def strip(s):
  66.     '''strip(s) -> string
  67.  
  68.     Return a copy of the string s with leading and trailing
  69.     whitespace removed.
  70.  
  71.     '''
  72.     return s.strip()
  73.  
  74.  
  75. def lstrip(s):
  76.     '''lstrip(s) -> string
  77.  
  78.     Return a copy of the string s with leading whitespace removed.
  79.  
  80.     '''
  81.     return s.lstrip()
  82.  
  83.  
  84. def rstrip(s):
  85.     '''rstrip(s) -> string
  86.  
  87.     Return a copy of the string s with trailing whitespace
  88.     removed.
  89.  
  90.     '''
  91.     return s.rstrip()
  92.  
  93.  
  94. def split(s, sep = None, maxsplit = 0):
  95.     '''split(str [,sep [,maxsplit]]) -> list of strings
  96.  
  97.     Return a list of the words in the string s, using sep as the
  98.     delimiter string.  If maxsplit is nonzero, splits into at most
  99.     maxsplit words If sep is not specified, any whitespace string
  100.     is a separator.  Maxsplit defaults to 0.
  101.  
  102.     (split and splitfields are synonymous)
  103.  
  104.     '''
  105.     return s.split(sep, maxsplit)
  106.  
  107. splitfields = split
  108.  
  109. def join(words, sep = ' '):
  110.     '''join(list [,sep]) -> string
  111.  
  112.     Return a string composed of the words in list, with
  113.     intervening occurrences of sep.  The default separator is a
  114.     single space.
  115.  
  116.     (joinfields and join are synonymous)
  117.  
  118.     '''
  119.     return sep.join(words)
  120.  
  121. joinfields = join
  122. _apply = apply
  123.  
  124. def index(s, *args):
  125.     '''index(s, sub [,start [,end]]) -> int
  126.  
  127.     Like find but raises ValueError when the substring is not found.
  128.  
  129.     '''
  130.     return _apply(s.index, args)
  131.  
  132.  
  133. def rindex(s, *args):
  134.     '''rindex(s, sub [,start [,end]]) -> int
  135.  
  136.     Like rfind but raises ValueError when the substring is not found.
  137.  
  138.     '''
  139.     return _apply(s.rindex, args)
  140.  
  141.  
  142. def count(s, *args):
  143.     '''count(s, sub[, start[,end]]) -> int
  144.  
  145.     Return the number of occurrences of substring sub in string
  146.     s[start:end].  Optional arguments start and end are
  147.     interpreted as in slice notation.
  148.  
  149.     '''
  150.     return _apply(s.count, args)
  151.  
  152.  
  153. def find(s, *args):
  154.     '''find(s, sub [,start [,end]]) -> in
  155.  
  156.     Return the lowest index in s where substring sub is found,
  157.     such that sub is contained within s[start,end].  Optional
  158.     arguments start and end are interpreted as in slice notation.
  159.  
  160.     Return -1 on failure.
  161.  
  162.     '''
  163.     return _apply(s.find, args)
  164.  
  165.  
  166. def rfind(s, *args):
  167.     '''rfind(s, sub [,start [,end]]) -> int
  168.  
  169.     Return the highest index in s where substring sub is found,
  170.     such that sub is contained within s[start,end].  Optional
  171.     arguments start and end are interpreted as in slice notation.
  172.  
  173.     Return -1 on failure.
  174.  
  175.     '''
  176.     return _apply(s.rfind, args)
  177.  
  178. _float = float
  179. _int = int
  180. _long = long
  181. _StringType = type('')
  182.  
  183. def atof(s):
  184.     '''atof(s) -> float
  185.  
  186.     Return the floating point number represented by the string s.
  187.  
  188.     '''
  189.     if type(s) == _StringType:
  190.         return _float(s)
  191.     raise TypeError('argument 1: expected string, %s found' % type(s).__name__)
  192.  
  193.  
  194. def atoi(*args):
  195.     '''atoi(s [,base]) -> int
  196.  
  197.     Return the integer represented by the string s in the given
  198.     base, which defaults to 10.  The string s must consist of one
  199.     or more digits, possibly preceded by a sign.  If base is 0, it
  200.     is chosen from the leading characters of s, 0 for octal, 0x or
  201.     0X for hexadecimal.  If base is 16, a preceding 0x or 0X is
  202.     accepted.
  203.  
  204.     '''
  205.     
  206.     try:
  207.         s = args[0]
  208.     except IndexError:
  209.         raise TypeError('function requires at least 1 argument: %d given' % len(args))
  210.  
  211.     if type(s) == _StringType:
  212.         return _apply(_int, args)
  213.     raise TypeError('argument 1: expected string, %s found' % type(s).__name__)
  214.  
  215.  
  216. def atol(*args):
  217.     '''atol(s [,base]) -> long
  218.  
  219.     Return the long integer represented by the string s in the
  220.     given base, which defaults to 10.  The string s must consist
  221.     of one or more digits, possibly preceded by a sign.  If base
  222.     is 0, it is chosen from the leading characters of s, 0 for
  223.     octal, 0x or 0X for hexadecimal.  If base is 16, a preceding
  224.     0x or 0X is accepted.  A trailing L or l is not accepted,
  225.     unless base is 0.
  226.  
  227.     '''
  228.     
  229.     try:
  230.         s = args[0]
  231.     except IndexError:
  232.         raise TypeError('function requires at least 1 argument: %d given' % len(args))
  233.  
  234.     if type(s) == _StringType:
  235.         return _apply(_long, args)
  236.     raise TypeError('argument 1: expected string, %s found' % type(s).__name__)
  237.  
  238.  
  239. def ljust(s, width):
  240.     '''ljust(s, width) -> string
  241.  
  242.     Return a left-justified version of s, in a field of the
  243.     specified width, padded with spaces as needed.  The string is
  244.     never truncated.
  245.  
  246.     '''
  247.     n = width - len(s)
  248.     if n <= 0:
  249.         return s
  250.     return s + ' ' * n
  251.  
  252.  
  253. def rjust(s, width):
  254.     '''rjust(s, width) -> string
  255.  
  256.     Return a right-justified version of s, in a field of the
  257.     specified width, padded with spaces as needed.  The string is
  258.     never truncated.
  259.  
  260.     '''
  261.     n = width - len(s)
  262.     if n <= 0:
  263.         return s
  264.     return ' ' * n + s
  265.  
  266.  
  267. def center(s, width):
  268.     '''center(s, width) -> string
  269.  
  270.     Return a center version of s, in a field of the specified
  271.     width. padded with spaces as needed.  The string is never
  272.     truncated.
  273.  
  274.     '''
  275.     n = width - len(s)
  276.     if n <= 0:
  277.         return s
  278.     half = n / 2
  279.     if n % 2 and width % 2:
  280.         half = half + 1
  281.     
  282.     return ' ' * half + s + ' ' * (n - half)
  283.  
  284.  
  285. def zfill(x, width):
  286.     '''zfill(x, width) -> string
  287.  
  288.     Pad a numeric string x with zeros on the left, to fill a field
  289.     of the specified width.  The string x is never truncated.
  290.  
  291.     '''
  292.     if type(x) == type(''):
  293.         s = x
  294.     else:
  295.         s = repr(x)
  296.     n = len(s)
  297.     if n >= width:
  298.         return s
  299.     sign = ''
  300.     if s[0] in ('-', '+'):
  301.         sign = s[0]
  302.         s = s[1:]
  303.     
  304.     return sign + '0' * (width - n) + s
  305.  
  306.  
  307. def expandtabs(s, tabsize = 8):
  308.     '''expandtabs(s [,tabsize]) -> string
  309.  
  310.     Return a copy of the string s with all tab characters replaced
  311.     by the appropriate number of spaces, depending on the current
  312.     column, and the tabsize (default 8).
  313.  
  314.     '''
  315.     res = line = ''
  316.     for c in s:
  317.         if c == '\t':
  318.             c = ' ' * (tabsize - len(line) % tabsize)
  319.         
  320.         line = line + c
  321.         if c == '\n':
  322.             res = res + line
  323.             line = ''
  324.             continue
  325.     
  326.     return res + line
  327.  
  328.  
  329. def translate(s, table, deletions = ''):
  330.     '''translate(s,table [,deletechars]) -> string
  331.  
  332.     Return a copy of the string s, where all characters occurring
  333.     in the optional argument deletechars are removed, and the
  334.     remaining characters have been mapped through the given
  335.     translation table, which must be a string of length 256.
  336.  
  337.     '''
  338.     return s.translate(table, deletions)
  339.  
  340.  
  341. def capitalize(s):
  342.     '''capitalize(s) -> string
  343.  
  344.     Return a copy of the string s with only its first character
  345.     capitalized.
  346.  
  347.     '''
  348.     return s.capitalize()
  349.  
  350.  
  351. def capwords(s, sep = None):
  352.     '''capwords(s, [sep]) -> string
  353.  
  354.     Split the argument into words using split, capitalize each
  355.     word using capitalize, and join the capitalized words using
  356.     join. Note that this replaces runs of whitespace characters by
  357.     a single space.
  358.  
  359.     '''
  360.     if not sep:
  361.         pass
  362.     return join(map(capitalize, s.split(sep)), ' ')
  363.  
  364. _idmapL = None
  365.  
  366. def maketrans(fromstr, tostr):
  367.     '''maketrans(frm, to) -> string
  368.  
  369.     Return a translation table (a string of 256 bytes long)
  370.     suitable for use in string.translate.  The strings frm and to
  371.     must be of the same length.
  372.  
  373.     '''
  374.     global _idmapL
  375.     if len(fromstr) != len(tostr):
  376.         raise ValueError, 'maketrans arguments must have same length'
  377.     len(fromstr) != len(tostr)
  378.     if not _idmapL:
  379.         _idmapL = list(_idmap)
  380.     
  381.     L = _idmapL[:]
  382.     fromstr = map(ord, fromstr)
  383.     for i in range(len(fromstr)):
  384.         L[fromstr[i]] = tostr[i]
  385.     
  386.     return join(L, '')
  387.  
  388.  
  389. def replace(s, old, new, maxsplit = 0):
  390.     '''replace (str, old, new[, maxsplit]) -> string
  391.  
  392.     Return a copy of string str with all occurrences of substring
  393.     old replaced by new. If the optional argument maxsplit is
  394.     given, only the first maxsplit occurrences are replaced.
  395.  
  396.     '''
  397.     return s.replace(old, new, maxsplit)
  398.  
  399.  
  400. try:
  401.     ''.upper
  402. except AttributeError:
  403.     from stringold import *
  404.  
  405.  
  406. try:
  407.     from strop import maketrans, lowercase, uppercase, whitespace
  408.     letters = lowercase + uppercase
  409. except ImportError:
  410.     pass
  411.  
  412.